﻿CREATE FUNCTION [maint].[GetBackupSetGroupName]
(@DbName [sysname])
RETURNS NVARCHAR (128)
AS
BEGIN
	DECLARE @ReturnValue nvarchar(128)
	SELECT
		@ReturnValue = N'DBA_' 
		+ REPLACE([DbName],' ','_')
		+ N'_' 
		+ [BackupAgent]
		+ N'_BACKUPSET'
	FROM [config].[DbMaintenance]
	WHERE  ([ServerName] = @@SERVERNAME)
		AND([DbName] = @DbName)

	RETURN(@ReturnValue)
END